<template>
<div>
  <city-header></city-header>
  <city-search :cities="cities"></city-search>
  <city-list :hotCity="hotCity" :cities="cities" :letter="letter"></city-list>
  <city-alphabet :cities="cities" @change="handleLetterChange"></city-alphabet>
</div>
</template>

<script>
import axios from 'axios'
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data () {
    return {
      hotCity: [],
      cities: {},
      letter: ''
    }
  },
  created () {
    this.getCityList()
  },
  methods: {
    getCityList () {
      axios.get('/api/city.json').then(this.getCityInfoSucc)
    },
    getCityInfoSucc (res) {
      res = res.data
      console.log(res)
      if (res.ret && res.data) {
        this.hotCity = res.data.hotCities
        this.cities = res.data.cities
      }
    },
    // 监听change事件
    handleLetterChange (letter) {
      // console.log(letter)
      this.letter = letter
    }
  }
}
</script>

<style lang="stylus" scoped>

</style>
